package com.woniuxy.goods.service.consumer;

import com.woniuxy.goods.entity.Goods;
import com.woniuxy.goods.param.AddExecuteParam;
import com.woniuxy.goods.param.AddUpGoodsLogParam;
import com.woniuxy.goods.service.ProcessExecuteService;
import com.woniuxy.goods.service.UpgoodsLogService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * login_code_queue队列消费者
 */
@Component
@RabbitListener(queues="sava_goods_queue")//接受消息队列里的参数
public class SavaGoodsConsumer {
    /**
     * 流程执行服务层接口
     */
    @Resource
    private ProcessExecuteService executeService;

    /**
     * 典当物品日志管理服务层接口
     */
    @Resource
    private UpgoodsLogService upgoodsLogService;

    /**
     * 新增物品流程执行和日志
     * @param goods 保存的物品对象
     * @throws Exception
     */
    @RabbitHandler
    public void savaGoods(Goods goods) throws Exception {
        System.out.println("==========================================");
        System.out.println(goods);
        //创建流程执行记录表
        AddExecuteParam executeParam = new AddExecuteParam();
        executeParam.setGoodsId(goods.getGoodsId());
        executeParam.setShopId(goods.getShopId());
        executeService.addExecute(executeParam);
        //新增日志
        AddUpGoodsLogParam logParam = new AddUpGoodsLogParam();
        logParam.setGoodsId(goods.getGoodsId());
        logParam.setModifyBy(goods.getInputUser());
        logParam.setUpdateDetails("新增典当物品");
        upgoodsLogService.addUpGoodsLog(logParam);
    }
}
